package qc.module.iot.protocol.ddp;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * DDP_V30 Dsc端发送的包类型
 *
 * @author QuCheng Tech
 * @since 2025/11/9
 */
@Getter
@AllArgsConstructor
public enum DDP_V30_DscSendPacketsTypeEnum {
    UN_DEFINE(0, "未定义"),
    LOGON_IN_SUCCESS(0x81, "注册成功"),
    LOGON_OUT_SUCCESS(0x82, "注销成功"),//DSC向DTU发送此指令时会让DTU重新启动
    RE_LOGON_IN(0x83, "重新注册"),//DSC要求DTU向DSC重注册
    INVALID(0x84, "无效命令或协议包"),//一般不使用
    RECEIVE_USER_DATA(0x85, "接收到DTU用户数据的应答包"),
    SEND_USER_DATA(0x89, "发送给DTU的用户数据包"),
    QUERY_PARAM(0x8B, "查询DTU参数"),
    SET_PARAM(0x8D, "设置DTU参数"),
    QUERY_LOG(0x8E, "提取DTU日志"),
    UPGRADE(0x8F, "远程升级");//DSC通知DTU远程升级的数据包

    @EnumValue
    private int index;
    private String name;

    @Override
    public String toString() {
        if (this != null)
            return this.name;

        return null;
    }

    /**
     * 根据int数值获取对应的枚举
     *
     * @param index 数值，限制为1字节
     * @return qc.module.iot.protocol.ddp.DDP_V30_DscSendPacketsTypeEnum
     * @author QuCheng Tech
     * @since 2025/11/9
     */
    public static DDP_V30_DscSendPacketsTypeEnum getDDP_V30_DscSendPacketsTypeEnum(int index) {
        if (index > 0x0) {
            int byteIntValue = index & 0xFF;//传入的值限制为1字节，最大0xFF
            if (byteIntValue > 0x0) {
                for (DDP_V30_DscSendPacketsTypeEnum item : DDP_V30_DscSendPacketsTypeEnum.values()) {
                    if (item.getIndex() == byteIntValue) {//判断序号使用getIndex，判断内容使用getName
                        return item;
                    }
                }
            }
        }
        return DDP_V30_DscSendPacketsTypeEnum.UN_DEFINE;
    }
}
